﻿using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Net5ApiAndEfMySql.API.Common;
using Net5ApiAndEfMySql.IRepository.SystemAdmin;
using Net5ApiAndEfMySql.IService;
using Net5ApiAndEfMySql.IService.SystemAdmin;
using Net5ApiAndEfMySql.Repository;
using Net5ApiAndEfMySql.Repository.SystemAdmin;
using Net5ApiAndEfMySql.Service;
using Net5ApiAndEfMySql.Service.SystemAdmin;
using Net5CommonLib.SystemLib.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Net5ApiAndEfMySql.ApiProjectTestDemo.RepositoryEfTest
{
   public class RepositoryEfTestBase
    {
        public RepositoryEfTestBase()
        {
            IConfiguration Configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", true, true)
// .AddJsonFile("appsettings.Development.json", true, true)
.Build();
            IServiceCollection iServiceCollection = new ServiceCollection();
            iServiceCollection.AddControllers();
            iServiceCollection.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            iServiceCollection.AddSingleton(Configuration);

            //配置Ef链接对象注入
            iServiceCollection.AddDbContext<SoaSystemCenterDbContext>(
                options =>
         options.UseMySql(connectionString: Configuration.GetSection("ConnectionStrings")["SoaSystemCenterMysqlConnection"],
          serverVersion: new MySqlServerVersion(new Version(5, 7, 21))
                           ));
            //iServiceCollection.AddSingleton<Log4Tools>();//以单例模式注入日志
            iServiceCollection.AddScoped<IOperatorService,  OperatorService>();
            iServiceCollection.AddScoped<IOperatorRepository, OperatorRepository>();

            iServiceCollection.AddScoped<IRoleDbService, RoleDbService>();
            iServiceCollection.AddScoped<IRoleDbRepository, RoleDbRepository>();

            iServiceCollection.AddScoped<IBaseService, BaseService>();

            //过滤器
            iServiceCollection.AddScoped<UserTokenVerificationAttribute>();

            DiManager.Instance = iServiceCollection.BuildServiceProvider();



        }
    }
}
